<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <style>
        .hide {
            display: none;
        }

        .c1 {
            position: fixed;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            background: rgba(0, 0, 0, .5);
            z-index: 2;
        }

        .c2 {
            background-color: white;
            position: fixed;
            width: 300px;
            height: 200px;
            top: 50%;
            left: 50%;
            z-index: 3;
            margin-top: -150px;
            margin-left: -150px;
            padding-top: 2%;
            padding-left: 2%;
        }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            客户抱怨附件查看
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <div
            style="background-color:white; width: 100%;margin-top:2%;white-space: nowrap;overflow-x: auto;-webkit-overflow-scrolling:touch;">
            <table class="table" style='width:700px;' id="table1">
                <tbody style="display:block">
                    <tr
                        style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-size: 15px;font-weight: bold;">
                        <td algin='center' style="width:50px">序号</td>
                        <td algin='center' style="width:300px">文件名</td>
                        <td algin='center' style="width:250px">上传时间</td>
                        <td algin='center' style="width:100px">文件预览</td>
                    </tr>
                </tbody>
            </table>
            <table class="table" style='width:700px;' id="table">
                <tbody id="fileDataHtml" style="display: block;height: 500px;overflow-y: scroll;">
                </tbody>
            </table>
        </div>
        <div id="shade" class="c1 hide"></div>
        <div id="modal" class="c2 hide">
            <p style="margin-left: 10px;font-size: 0.8rem;font-weight: 500;color: #212121;text-align: center;">
                请填写审核不通过原因</p>
            <ul class="aui-list aui-form-list" style="margin-top: 4%;">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">原因：</div>
                        <div class="aui-list-item-input">
                            <textarea id="reason"></textarea>
                        </div>
                    </div>
                </li>
            </ul>
            <footer class="aui-bar aui-bar-tab" style="position: absolute;">
                <div class="aui-btn aui-btn-info" style="width:30%;margin-left:2%;" onclick="Hide()">取消
                </div>
                <div class="aui-btn aui-btn-info" style="width:30%;margin-left:10%;" onclick="doSave('th')">确定</div>
            </footer>
        </div>
    </div>
    <!-- 
    <footer class="aui-bar aui-bar-tab" id="footer">
        <div class="aui-bar-tab-item" tapmode id="scan" onclick="doScan()">
            <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
        </div>
    </footer> -->
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    var ids = "";
    //初始化
    apiready = function () {
        ids = api.pageParam.ids;
        doSearch();
    }

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //查询
    //查询
    function doSearch() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/qcKmManageDocumentView";
        var data = {
            values: {
                ids: ids,
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                console.log("文件List：" + JSON.stringify(myobj.list));

                //成功
                if (myobj.code == 0) {

                    //班組賦值
                    var list = eval(myobj.list);
                    var html = "";
                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        html += "<tr style='text-align: center;color: black;font-size: 12px;background-color: #F5F5F5;'>";
                        html += "<td style='width:50px;' name='index'>" + (i + 1) + "</td>";
                        html += "<td style='width:300px;' name='fileName'>" + list[i].fileName + "</td>";
                        html += "<td style='width:250px;'name='createDate'>" + list[i].createDate + "</td>";
                        html += "<td style='width:100px;'name='teamName'> <button style = 'background-color:green' onclick='openFile(\"" + list[i].sysid + "\",\"" + list[i].fileName + "\")'>预览</button></td>";
                        html += "</tr>";
                    }

                    $api.html($api.byId("fileDataHtml"), html);
                } else {
                    $api.html($api.byId("fileDataHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //文件预览
    function openFile(docId, fileName) {
        var serverUrl = localStorage.getItem('serverUrl');
        var downloadUrl = serverUrl + `/app/openFile/` + docId;
        api.download({
            url: downloadUrl,
            report: true,
            savePath: 'fs://' + fileName,
        }, function (ret, err) {
            if (ret && 1 == ret.state) { /* 下载完成 */
                // console.log("下载成功savePath:" + ret.savePath);

                // 打开文件
                var docReader = api.require('docReader');

                docReader.open({
                    path: 'fs://' + fileName
                }, function (ret, err) {
                    if (ret.status) {
                        console.log("文件打开成功：" + ret);
                    } else {
                        alert(JSON.stringify("此文件不存在！"));
                    }
                });
            }

            if (ret && 2 == ret.state) {
                console.log("下载失败");
            }
        });
    }

    // function changeStateNew(type) {
    //     document.getElementById('modal').classList.remove('hide');
    //     document.getElementById('shade').classList.remove('hide');
    // }

    // function Hide() {
    //     document.getElementById('modal').classList.add('hide');
    //     document.getElementById('shade').classList.add('hide');
    // }

    // function doSave(type) {
    //     document.getElementById('modal').classList.add('hide');
    //     document.getElementById('shade').classList.add('hide');
    //     changeState(type)
    // }

    function changeState(type) {
        //选中数据
        var check = $("input[type='checkbox']:checked"); //在table中找input下类型为checkbox属性为选中状态的数据
        var count = 0;
        check.each(function () {
            count++;
        });

        //选中行不为1
        if (count == 0) {
            api.toast({
                msg: '请选择至少一条数据！',
                duration: 3000
            });
            return;
        }
        var ids = "";
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            var sysid = row.find("[name='sysid']").html();

            ids += "" + sysid + ","
        });

        if (ids) {
            ids = ids.substring(0, ids.length - 1);
        }
        if (type == 'view') {

        }
        else if (type == 'file') {

        }

        api.openWin({
            name: 'qckmmanage-assign-detail',
            url: 'qckmmanage-assign-detail.html',
            pageParam: {
                name: "qckmmanage-assign",
                ids: ids,
            }
        });
    }

    function closeDialog() {
        var dialogBox = api.require('dialogBox');
        dialogBox.close({
            dialogName: 'input'
        });
    }

    //订单返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>